#ifndef __ROAD__
#define __ROAD__

#include "Header.h"
#include "GameObject.h"

#define kG 9.8*METTER_TO_POINT
#define kK 0.7

enum BusLaneMode
{
	BLM_BUS = 0,
	BLM_BUS_MOTOR,
	BLM_ALL
};

class Vehicle;

class Road : public GameObject
{
public:
	Road();
	~Road();

	bool init(CCSize size);
	void draw();
	void start();

	CCArray* getVehicles();
	float getlane3Y();
	float getLane1Y();
	float getLane2Y();
	float getRoadWidth();
	float getLaneWidth();
	bool getIsGreenLightOn();
	int getBusLaneMode();
	bool isAllowTurnToBusLane(int vehicleType);
	bool checkVehicleCanTurnBusLaneMode(CCRect safeRect, int vehicleType);

	// lane 1 is bus lane (top lane on screen / left lane on real), lane 2 center, lane 3 bottom.
	int getWhichLane(Vehicle* vehicle);
	int getWhichLane(CCRect rect);

	// return -1 if not entire in lane
	int rectEntireInLane(CCRect rect);

private:
	int treeDistance;
	float lane3Y;
	float lane1Y;
	float lane2Y;
    
    float lane11Y;
    float lane12Y;
    float lane13Y;
    float lane14Y;
    float lane15Y;
    float lane16Y;
    float lane17Y;
    float lane18Y;

	CCArray* vehicles;

	bool isGreenLightOn;
	int greenLightTime;
	int redLightTime;
	bool isRunning;
	int trafficLightTimeRemaining;
	int busLaneMode;
	CCTimer* oneSecondTimer;

	CCSprite* trafficLightSprite;
	CCLabelTTF* trafficTimeRemainingLabel;

	void addVehicle(Vehicle* vehicle, int LaneIndex);
	void oneSecondTick(float t);
	void update(float delta);
	void checkToRemoveVehicle();

	void setTrafficLightColor(bool isGreen);
    void addVehicle(VehicleData* vehicleData);
};
#endif // !__ROAD__
